
package com.xx.entity;

import java.io.Serializable;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 
 * @TableName cqcet.session
 * @description 登录日志 未启用Redis的情况下记录登录数据
 */
@Data
@TableName("cqcet.session")
@ApiModel
public class Session implements Serializable {
    
	/**
	 * token
	 */
	@TableId(type = IdType.ASSIGN_ID)
	@ApiModelProperty("token")
	@JsonSerialize(using = ToStringSerializer.class)
	private String id;
			
    /**
     * 会话密钥
	 * 
     */
    @ApiModelProperty("会话密钥")
    private String session_key;
				
    /**
     * userId
	 * 
     */
    @ApiModelProperty("userId")
    private String userId;
				
    /**
     * 用户账号
	 * 
     */
    @ApiModelProperty("用户账号")
    private String userName;
				
    /**
     * 登录类型
	 * 
     */
    @ApiModelProperty("登录类型")
    private String type;
				
    /**
     * 地址
	 * 
     */
    @ApiModelProperty("地址")
    private String address;
				
    /**
     * 登录平台
	 * 
     */
    @ApiModelProperty("登录平台")
    private String platform;
				
    /**
     * 登录时间
	 * 
     */
    @ApiModelProperty("登录时间")
    private String inTime;
				
    /**
     * 退出时间
	 * 
     */
    @ApiModelProperty("退出时间")
    private String outTime;
				
	/**
	 * 创建时间
	 */
	@TableField(fill = FieldFill.INSERT)
	@ApiModelProperty("创建时间")
	@JsonSerialize(using = ToStringSerializer.class)
	private Long createTime;
				  
	/**
	 * 上次更新时间
	 */
	@TableField(fill = FieldFill.UPDATE)
	@ApiModelProperty("上次更新时间")
	@JsonSerialize(using = ToStringSerializer.class)
	private Long updateTime;
					
	/**
	 * 创建时间
	 */
	@TableField(fill = FieldFill.INSERT)
	@ApiModelProperty("创建时间")
	private String createTimeString;
					
	/**
	 * 更新时间
	 */
	@TableField(fill = FieldFill.UPDATE)
	@ApiModelProperty("更新时间")
	private String updateTimeString;
					
	/**
	 * 逻辑删除控制
	 */
	@ApiModelProperty("逻辑删除控制")
	@TableLogic
	private Integer state;
			  
	/**
	 * 单位
	 */
	@TableField(fill = FieldFill.INSERT)
	@ApiModelProperty("单位")
	private String unitId;
					
	
	/**
	 * 设置token
	 */
	public void setId(String id){
		this.id = id;
	}

	/**
	 * 获取token
	 */
	public String getId(){
		return this.id;
	}
		
	/**
	 * 设置会话密钥
	 */
	public void setSessionKey(String session_key){
		this.session_key = session_key;
	}

	/**
	 * 获取会话密钥
	 */
	public String getSessionKey(){
		return this.session_key;
	}
		
	/**
	 * 设置userId
	 */
	public void setUserId(String userId){
		this.userId = userId;
	}

	/**
	 * 获取userId
	 */
	public String getUserId(){
		return this.userId;
	}
		
	/**
	 * 设置用户账号
	 */
	public void setUserName(String userName){
		this.userName = userName;
	}

	/**
	 * 获取用户账号
	 */
	public String getUserName(){
		return this.userName;
	}
		
	/**
	 * 设置登录类型
	 */
	public void setType(String type){
		this.type = type;
	}

	/**
	 * 获取登录类型
	 */
	public String getType(){
		return this.type;
	}
		
	/**
	 * 设置地址
	 */
	public void setAddress(String address){
		this.address = address;
	}

	/**
	 * 获取地址
	 */
	public String getAddress(){
		return this.address;
	}
		
	/**
	 * 设置登录平台
	 */
	public void setPlatform(String platform){
		this.platform = platform;
	}

	/**
	 * 获取登录平台
	 */
	public String getPlatform(){
		return this.platform;
	}
		
	/**
	 * 设置登录时间
	 */
	public void setInTime(String inTime){
		this.inTime = inTime;
	}

	/**
	 * 获取登录时间
	 */
	public String getInTime(){
		return this.inTime;
	}
		
	/**
	 * 设置退出时间
	 */
	public void setOutTime(String outTime){
		this.outTime = outTime;
	}

	/**
	 * 获取退出时间
	 */
	public String getOutTime(){
		return this.outTime;
	}
		
	/**
	 * 设置创建时间
	 */
	public void setCreateTime(Long createTime){
		this.createTime = createTime;
	}

	/**
	 * 获取创建时间
	 */
	public Long getCreateTime(){
		return this.createTime;
	}
		
	/**
	 * 设置上次更新时间
	 */
	public void setUpdateTime(Long updateTime){
		this.updateTime = updateTime;
	}

	/**
	 * 获取上次更新时间
	 */
	public Long getUpdateTime(){
		return this.updateTime;
	}
		
	/**
	 * 设置创建时间
	 */
	public void setCreateTimeString(String createTimeString){
		this.createTimeString = createTimeString;
	}

	/**
	 * 获取创建时间
	 */
	public String getCreateTimeString(){
		return this.createTimeString;
	}
		
	/**
	 * 设置更新时间
	 */
	public void setUpdateTimeString(String updateTimeString){
		this.updateTimeString = updateTimeString;
	}

	/**
	 * 获取更新时间
	 */
	public String getUpdateTimeString(){
		return this.updateTimeString;
	}
		
	/**
	 * 设置逻辑删除控制
	 */
	public void setState(Integer state){
		this.state = state;
	}

	/**
	 * 获取逻辑删除控制
	 */
	public Integer getState(){
		return this.state;
	}
		
	/**
	 * 设置单位
	 */
	public void setUnitId(String unitId){
		this.unitId = unitId;
	}

	/**
	 * 获取单位
	 */
	public String getUnitId(){
		return this.unitId;
	}
		
	public String stringify(){
		String rc = "{\"id\":\"" + this.getId() + "\",\"session_key\":\"" + this.getSessionKey() + "\",\"userId\":\"" + this.getUserId() + "\",\"userName\":\"" + this.getUserName() + "\",\"type\":\"" + this.getType() + "\",\"address\":\"" + this.getAddress() + "\",\"platform\":\"" + this.getPlatform() + "\",\"inTime\":\"" + this.getInTime() + "\",\"outTime\":\"" + this.getOutTime() + "\",\"createTime\":\"" + this.getCreateTime() + "\",\"updateTime\":\"" + this.getUpdateTime() + "\",\"createTimeString\":\"" + this.getCreateTimeString() + "\",\"updateTimeString\":\"" + this.getUpdateTimeString() + "\",\"state\":\"" + this.getState() + "\",\"unitId\":\"" + this.getUnitId() + "\"}";
		rc = rc.replaceAll("\"null\"","null").replaceAll("\"([0-9]+)\"","$1");
        return rc;
	}

	public static Session JSONparse(String jsonString) throws JsonProcessingException {
        if(jsonString == null) return null;
		try {
            ObjectMapper objectMapper = new ObjectMapper();
            return objectMapper.readValue(jsonString,Session.class);
        }catch (JsonProcessingException e){
            return null;
        }
    }
}
    